//
//  DMLifecycleTypes.h
//  DualMediationSDK
//
//  生命周期管理相关类型定义
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

#pragma mark - 生命周期状态枚举

/**
 * iOS应用生命周期状态
 */
typedef NS_ENUM(NSInteger, DMLifecycleState) {
    DMLifecycleStateUnknown = 0,        // 未知状态
    DMLifecycleStateLaunching,          // 启动中
    DMLifecycleStateActive,             // 活跃状态
    DMLifecycleStateInactive,           // 非活跃状态
    DMLifecycleStateForeground,         // 前台状态
    DMLifecycleStateBackground,         // 后台状态
    DMLifecycleStateSuspended,          // 挂起状态
    DMLifecycleStateTerminating,        // 终止中
    DMLifecycleStateTerminated          // 已终止
};

/**
 * 生命周期事件类型
 */
typedef NS_ENUM(NSInteger, DMLifecycleEvent) {
    DMLifecycleEventUnknown = 0,                    // 未知事件
    DMLifecycleEventDidFinishLaunching,             // 启动完成
    DMLifecycleEventDidBecomeActive,                // 变为活跃
    DMLifecycleEventWillResignActive,               // 将要失去活跃
    DMLifecycleEventDidEnterBackground,             // 进入后台
    DMLifecycleEventWillEnterForeground,            // 将要进入前台
    DMLifecycleEventWillTerminate,                  // 将要终止
    DMLifecycleEventDidReceiveMemoryWarning,        // 收到内存警告
    DMLifecycleEventDidReceiveRemoteNotification,   // 收到远程通知
    DMLifecycleEventDidReceiveLocalNotification,    // 收到本地通知
    DMLifecycleEventOpenURL,                        // 打开URL
    DMLifecycleEventContinueUserActivity            // 继续用户活动
};

#pragma mark - 产品相关枚举

/**
 * 产品类型
 */
typedef NS_ENUM(NSInteger, DMProductType) {
    DMProductTypeConsumable = 0,        // 消耗型产品
    DMProductTypeNonConsumable,         // 非消耗型产品
    DMProductTypeSubscription           // 订阅型产品
};

#pragma mark - 常量定义

#pragma mark - 通知 & UserInfo Key
FOUNDATION_EXPORT NSString * const DMLifecycleManagerDidChangeStateNotification;
FOUNDATION_EXPORT NSString * const DMLifecycleManagerDidReceiveEventNotification;
FOUNDATION_EXPORT NSString * const DMLifecycleManagerStateKey;
FOUNDATION_EXPORT NSString * const DMLifecycleManagerEventKey;
FOUNDATION_EXPORT NSString * const DMLifecycleManagerUserInfoKey;

#pragma mark - 代理优先级
FOUNDATION_EXPORT const NSInteger DMLifecycleDelegatePriorityHigh;   // 1000
FOUNDATION_EXPORT const NSInteger DMLifecycleDelegatePriorityNormal; //  500
FOUNDATION_EXPORT const NSInteger DMLifecycleDelegatePriorityLow;    //    0

#pragma mark - 错误域 & 错误码
FOUNDATION_EXPORT NSString * const DMLifecycleErrorDomain;

typedef NS_ENUM(NSInteger, DMLifecycleErrorCode) {
    DMLifecycleErrorCodeUnknown           = 0,
    DMLifecycleErrorCodeInvalidState      = 1,
    DMLifecycleErrorCodeInvalidTransition = 2,
    DMLifecycleErrorCodeDelegateNotFound  = 3,
    DMLifecycleErrorCodeListenerNotFound  = 4
};

#pragma mark - 内购回调类型定义

/**
 * 内购成功回调
 * @param responseObject 成功响应数据
 */
typedef void(^DMInAppPurchaseSuccessCallback)(id _Nullable responseObject);

/**
 * 内购失败回调
 * @param error 错误信息
 */
typedef void(^DMInAppPurchaseFailureCallback)(NSError * _Nonnull error);

/**
 * 商品列表回调
 * @param productList 商品列表数组
 */
typedef void(^DMProductListCallback)(NSArray * _Nullable productList);

/**
 * 未核销订单回调
 * @param orders 未核销订单数组
 */
typedef void(^DMUnacknowledgedOrdersCallback)(NSArray * _Nullable orders);

#pragma mark - 工具函数
FOUNDATION_EXPORT NSString *DMLifecycleStateDescription(DMLifecycleState state);
FOUNDATION_EXPORT NSString *DMLifecycleEventDescription(DMLifecycleEvent event);
FOUNDATION_EXPORT BOOL     DMLifecycleIsValidStateTransition(DMLifecycleState fromState,
                                                             DMLifecycleState toState);

NS_ASSUME_NONNULL_END
